/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.entity;

import com.paris5.master2.guitarmaster.bean.EcomScore;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 */
@Entity
@Table(name = "score")
public class Score implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_score")
    private Integer idScore;
    
    @Column(name = "vote_count")
    private int voteCount;
    
    @Column(name = "vote_value")
    private int voteValue;

    @Column(name = "score")
    private int score;

    public Score() {
    }

    public Score(Integer idScore) {
        this.idScore = idScore;
    }

    public Score(Integer idScore, int voteCount, int value) {
        this.idScore = idScore;
        this.voteCount = voteCount;
        this.voteValue = value;
        this.setScore();
    }
    
    public Score(EcomScore es) {
        this.idScore = es.getId();
        this.voteCount = es.getVoteCount();
        this.voteValue = es.getVoteValue();
        this.score = es.getScore();
    }
    
    public EcomScore getEcomScore(){
        EcomScore es = new EcomScore(idScore, voteCount, voteValue);
        return es;
    }
    
    public Integer getIdScore() {
        return idScore;
    }

    public void setIdScore(Integer idScore) {
        this.idScore = idScore;
    }

    public int getVoteCount() {
        return voteCount;
    }

    public void setVoteCount(int voteCount) {
        this.voteCount = voteCount;
        this.setScore();
    }

    public void setVoteValue(int voteValue) {
        this.voteValue = voteValue;
        this.setScore();
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public int getVoteValue() {
        return voteValue;
    }
    
    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
    
    public final void setScore() {
        this.score = (this.voteValue *100) /this.voteCount;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idScore != null ? idScore.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Score)) {
            return false;
        }
        Score other = (Score) object;
        if ((this.idScore == null && other.idScore != null) || (this.idScore != null && !this.idScore.equals(other.idScore))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.paris5.master2.guitarmaster.entity.Score[ idScore=" + idScore + " ]";    
    }
    
}
